package com.youtellv1.mapper;

import com.youtellv1.entity.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper extends BaseMapper<Admin> {
    @Select("select * from tb_admins")
    List<Admin> findAllAdmin();
    
    @Select("select * from tb_admins where aid = #{aid}")
    Admin findAdminById(Admin admin);

    @Select("select * from tb_admins where account = #{account} and password = #{password}")
    Admin findByAccountAndPassword(Admin admin);

    @Select("select * from tb_admins where account = #{account}")
    Admin findByAccount(Admin admin);

    @Select("select * from tb_admins where password = #{password}")
    Admin findByPassword(Admin admin);
    
    @Insert("insert into tb_admins(account, password) values (#{account}, #{password})")
    void save(Admin admin);
    
    @Update("<script>" +
            "update tb_admins " +
            "<set>" +
            "    <if test='account != null'>account = #{account},</if>" +
            "    <if test='password != null'>password = #{password}</if>" +
            "</set>" +
            "where aid = #{aid}" +
            "</script>")
    void update(Admin admin);
    
    @Delete("delete from tb_admins where aid = #{aid}")
    void delete(Admin admin);
}
